<?php
namespace Face\Controller;
class IndexController extends CommonController {
    /*前台首页*/
    public function index(){
        /*轮播图*/
        $this->assign('ban',M('slide')->limit(3)->order('slide_id desc')->select());
        /*分类*/
        $this->assign('type',M('goodstype')->limit(5)->order('id asc')->select());
        /*新品*/
        $this->assign('new',M('goods')->where(['goods_hot'=>1,'goods_shangjia'=>1])->limit(4)->order('id desc')->select());
        /*热销*/
        $this->assign('hot',M('goods')->where(['goods_hot'=>0,'goods_shangjia'=>1])->limit(4)->order('id desc')->select());
        /*精品*/
        $this->assign('mas',M('goods')->where(['goods_hot'=>2,'goods_shangjia'=>1])->limit(4)->order('id desc')->select());
        $this->display();
    }
    /*商品列表 默认*/
    public function good()
    {
        $count      = M('goods')->where(['goods_shangjia'=>1])->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(10)
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();// 分页显示输出

        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = M('goods')->where(['goods_shangjia'=>1])->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign(['page'=>$show,'data'=>$list]);

        $this->display();
    }

    /*商品列表 销量*/
    public function xiaoliang()
    {
        $count      = M('goods')->where(['goods_shangjia'=>1])->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(10)
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();// 分页显示输出

        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = M('goods')->where(['goods_shangjia'=>1])->order('goods_chengjiao desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign(['page'=>$show,'data'=>$list]);

        $this->display();
    }
    /*主页热销商品*/
    public function hot()
    {
        $count      = M('goods')->where(['goods_hot'=>0,'goods_shangjia'=>1])->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(10)
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();// 分页显示输出

        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = M('goods')->where(['goods_hot'=>0,'goods_shangjia'=>1])->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign(['page'=>$show,'data'=>$list]);

        $this->display();
    }
    /*主页精品商品*/
    public function best()
    {
        $count      = M('goods')->where(['goods_hot'=>2,'goods_shangjia'=>1])->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(10)
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();// 分页显示输出

        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = M('goods')->where(['goods_hot'=>2,'goods_shangjia'=>1])->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign(['page'=>$show,'data'=>$list]);

        $this->display();
    }
    /*商品列表 价格*/
    public function xiaoshou()
    {
        $count      = M('goods')->where(['goods_shangjia'=>1])->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(10)
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();// 分页显示输出

        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = M('goods')->where(['goods_shangjia'=>1])->order('goods_xiaoshou desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign(['page'=>$show,'data'=>$list]);

        $this->display();
    }

    /*商品列表 时间*/

    public function time()
    {
        $count      = M('goods')->where(['goods_shangjia'=>1])->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(10)
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();// 分页显示输出

        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = M('goods')->where(['goods_shangjia'=>1])->order('goods_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign(['page'=>$show,'data'=>$list]);

        $this->display();
    }

    /*商品 搜索*/

    public function ser()
    {
        $ser = i('post.ser');
        $where= array('like','%'.$ser.'%');
        if(IS_POST){
            if(trim(empty($ser))){
                $this->redirect('Face/Index/kong');
            }
            $count      = M('goods')->where(['goods_name'=>$where,'goods_shangjia'=>1])->count();// 查询满足要求的总记录数
            if($count==0){
                $this->redirect('Face/Index/kong');
            }
            $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(10)
            $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
            $show       = $Page->show();// 分页显示输出

            // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
            $list = M('goods')->where(['goods_name'=>$where,'goods_shangjia'=>1])->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
            /*
            echo '<pre/>';
            var_dump($list);
            die();
            */
            $this->assign(['page'=>$show,'data'=>$list]);
            $this->display();
        }else{
            $this->display();
        }
    }
    /*搜索为空*/
    public function kong()
    {
        $this->display();
    }
    /*商品内容页*/
    public function content()
    {
        $id = i('get.id');
        $data = M('goods')->where(['id'=>$id])->find();

            //$dd = implode('|',$data['goods_show']);

        $data['goods_show'] = explode('|',$data['goods_show']);
        /*
        echo '<pre/>';
        var_dump($data['goods_show']);
        die();
        */
        /*获取评论*/
        $pinglun = M('pinglun')->where(['goodid'=>$id])->select();
        $count = M('pinglun')->where(['goodid'=>$id])->count();

        $this->assign('count',$count);
        $this->assign('pinglun',$pinglun);
        $this->assign('voi',$data['goods_show']);
        $this->assign('vo',$data);
        $this->display();
    }
}